package com.qeegoo.b2bautozityp.moudle.home.viewmodel;

import android.databinding.ObservableField;

import com.kelin.mvvmlight.command.ReplyCommand;
import com.qeegoo.b2bautozityp.api.ProgressSubscriber;
import com.qeegoo.b2bautozityp.api.RequestApi;
import com.qeegoo.b2bautozityp.api.RetrofitService;
import com.qeegoo.b2bautozityp.moudle.goods.view.GoodsManagerActivity;
import com.qeegoo.b2bautozityp.moudle.home.model.MainOrderIndexBean;
import com.qeegoo.b2bautozityp.moudle.home.view.MainActivity;
import com.qeegoo.b2bautozityp.moudle.inquiry.view.InquiryListActivity;
import com.qeegoo.b2bautozityp.moudle.login.view.LoginActivity;
import com.qeegoo.b2bautozityp.moudle.order.view.OrderListActivity;
import com.qeegoo.b2bautozityp.moudle.statis.view.StatisActivity;

import base.lib.util.ActivityManager;
import base.lib.util.NavigateUtils;

/**
 * 王少岩 在 2017/9/13 创建了它
 */

public class MainViewModel {

    private RequestApi mRequestApi;

    public ObservableField<String> wSend = new ObservableField<>("0");//待发货
    public ObservableField<String> wTake = new ObservableField<>("0");//待收货
    public ObservableField<String> wPrice = new ObservableField<>("0");//待报价
    public ReplyCommand orderCommand = new ReplyCommand(()->{
        NavigateUtils.startActivity(OrderListActivity.class);
    });
    public ReplyCommand askCommand = new ReplyCommand(()->{
        NavigateUtils.startActivity(InquiryListActivity.class);
    });
    public ReplyCommand statisCommand = new ReplyCommand(()->{
//        NavigateUtils.startActivity(LoginActivity.class);
        NavigateUtils.startActivity(StatisActivity.class);
    });
    public ReplyCommand goodsCommand = new ReplyCommand(()-> NavigateUtils.startActivity(GoodsManagerActivity.class));
    public ReplyCommand leftCommand = new ReplyCommand(()->{
        ((MainActivity)ActivityManager.getActivity()).showDrawerLayout();
    });
    public ReplyCommand loginCommand = new ReplyCommand(()->{
        NavigateUtils.startActivity(LoginActivity.class);
    });

    public MainViewModel(RequestApi requestApi) {
        mRequestApi = requestApi;
    }
    public void loadHttp(){
        mRequestApi.mainOrderIndex().compose(RetrofitService.applySchedulers())
                .map(new RetrofitService.HttpResultFunc<>())
                .subscribe(new ProgressSubscriber<MainOrderIndexBean>() {
                    @Override
                    public void onNext(MainOrderIndexBean mainOrderIndexBean) {
                        wSend.set(mainOrderIndexBean.waitPriceCount);
                        wTake.set(mainOrderIndexBean.captionCount);
                        wPrice.set(mainOrderIndexBean.deliveredCount);
                    }
                });
    }
}
